package com.edu.lxshpc.handler;

import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson2.JSON;
import com.edu.lxshpc.utils.Result;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @author zgh
 * @date 2023/10/28
 * 注销成功处理器
 */
@Component
@Slf4j
public class MyLogoutHandler implements LogoutSuccessHandler {
    @Override
    public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
        log.info("进入自定义注销成功处理器");
        //TODO
        //清除登录信息
        Result result = Result.success();
        String s = JSONUtil.toJsonStr(result);
        response.setCharacterEncoding("UTF-8");
        response.setContentType("application/json");
        response.getWriter().println(s);
    }
}
